package com.ctshk.sapp.finance.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.bill.BillListDTO;
import com.ctshk.rpc.finance.dto.bill.BillRefundInfoDTO;
import com.ctshk.rpc.finance.dto.bill.BillRefundListDTO;
import com.ctshk.rpc.finance.dto.bill.BillToConfirmListDTO;
import com.ctshk.rpc.finance.req.bill.*;
import com.ctshk.rpc.finance.service.IFinanceBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 财务收款及退款单 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-26
 */
@RestController
@Api(value = "认款管理", tags = "认款管理")
@RequestMapping("/finance-bill")
public class FinanceBillController extends BaseController {

    @DubboReference
    private IFinanceBillService billService;

    @ApiOperation(value = "列表", notes = "列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "认款列表", operDesc = "认款列表")
    @PostMapping("/list")
    public Result<PageResponse<BillListDTO>> list(@RequestBody BillListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billService.list(req);
    }

    @ApiOperation(value = "待确认列表", notes = "待确认列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "待确认列表", operDesc = "待确认列表")
    @PostMapping("/to-confirm-list")
    public Result<PageResponse<BillToConfirmListDTO>> toConfirmList(@RequestBody BillToConfirmListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billService.toConfirmList(req);
    }

    @ApiOperation(value = "批量ID获取列表", notes = "批量ID获取列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "批量ID获取列表", operDesc = "批量ID获取列表")
    @PostMapping("/batch-id-list")
    public Result<PageResponse<BillToConfirmListDTO>> batchIdList(@RequestBody @Valid BillBatchIdListListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billService.batchIdList(req);
    }

    @ApiOperation(value = "认款详情-收款单明细", notes = "认款详情-收款单明细（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "认款详情-收款单明细", operDesc = "认款详情-收款单明细")
    @PostMapping("/confirm-list")
    public Result<PageResponse<BillToConfirmListDTO>> confirmList(@RequestBody @Valid BillConfirmIdListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billService.confirmList(req);
    }

    @ApiOperation(value = "客户对账-客户未对账列表", notes = "客户对账-客户未对账列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "客户对账-客户未对账列表", operDesc = "客户对账-客户未对账列表")
    @PostMapping("/custom-uncheck-list")
    public Result<PageResponse<BillToConfirmListDTO>> customUncheckList(@RequestBody @Valid BillCustomIdListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billService.customUncheckList(req);
    }

    @ApiOperation(value = "对账详情-关联认款列表", notes = "对账详情-关联认款列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "对账详情-关联认款列表", operDesc = "对账详情-关联认款列表")
    @PostMapping("/check-list")
    public Result<PageResponse<BillToConfirmListDTO>> checkList(@RequestBody @Valid BillCheckIdListReq req) {
        return billService.checkList(req);
    }

    @ApiOperation(value = "销售订单退款列表", notes = "销售订单退款列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "销售订单退款列表", operDesc = "销售订单退款列表")
    @PostMapping("/refund-list")
    public Result<PageResponse<BillRefundListDTO>> refundList(@RequestBody @Valid BillRefundListReq req) {
        return billService.refundList(req);
    }

    @ApiOperation(value = "退款信息", notes = "销售订单退款-退款信息（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "销售订单退款-退款信息", operDesc = "销售订单退款-退款信息")
    @PostMapping("/refund-info")
    public Result<BillRefundInfoDTO> refundInfo(@RequestBody @Valid BillIdReq req) {
        return billService.refundInfo(req);
    }

    @ApiOperation(value = "退款-退款信息", notes = "销售订单退款-退款-退款信息（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "销售订单退款-退款-退款信息", operDesc = "销售订单退款-退款-退款信息")
    @PostMapping("/add-refund-info")
    public Result<BillRefundInfoDTO> addRefundInfo(@RequestBody @Valid BillIdReq req) {
        return billService.addRefundInfo(req);
    }

    @ApiOperation(value = "退款", notes = "销售订单退款-退款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "销售订单退款-退款", operDesc = "销售订单退款-退款")
    @PostMapping("/refund")
    public Result refund(@RequestBody @Valid BillRefundReq req) {
        req.setUser(getCurrentUser(getRequest()));
        return billService.refund(req);
    }

    @ApiOperation(value = "确认退款", notes = "销售订单退款-确认（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "销售订单退款-确认", operDesc = "销售订单退款-确认")
    @PostMapping("/confirm-refund")
    public Result confirmRefund(@RequestBody @Valid BillIdReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billService.confirmRefund(req);
    }

    @ApiOperation(value = "新增收款认款(内部接口)", notes = "新增收款认款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "新增收款认款", operDesc = "新增收款认款")
    @PostMapping("/add-collection")
    public Result addCollection(@RequestBody @Valid List<BillAddCollectionReq> req) {
        return billService.addCollection(req);
    }

    @ApiOperation(value = "新增退款认款(内部接口)", notes = "新增退款认款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "新增退款认款", operDesc = "新增退款认款")
    @PostMapping("/add-refund")
    public Result addRefund(@RequestBody @Valid List<BillAddRefundReq> req) {
        return billService.addRefund(req);
    }

    @ApiOperation(value = "操作退款(内部接口)", notes = "操作退款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "操作退款(内部接口)", operDesc = "操作退款(内部接口)")
    @PostMapping("/operate-refund")
    public Result operateRefund(@RequestBody @Valid BillOperateRefundReq req) {
        return billService.operateRefund(req);
    }

    @ApiOperation(value = "再次确认(内部接口)", notes = "再次确认（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "再次确认(内部接口)", operDesc = "再次确认(内部接口)")
    @PostMapping("/re-confirm")
    public Result reConfirm(@RequestBody @Valid BillOperateRefundReq req) {
        return billService.reConfirm(req);
    }


}
